package org.kitten.core.util;

import java.io.File;
import java.util.TimeZone;

import org.apache.log4j.PropertyConfigurator;

public class Log4jUtil {
	/**
	 * 初使化log4j参数.
	 */
	public static void init() {
		init("log4j.properties");
	}

	/**
	 * log4j属性文件的名字，默认为log4j.properties
	 * 
	 * @param log4jFileName
	 */
	public static void init(String log4jFileName) {
		TimeZone.setDefault(TimeZone.getTimeZone("GMT+8:00"));
		File logDir = new File(System.getProperty("user.dir") + File.separator
				+ "logs");
		if (!logDir.exists()) {
			logDir.mkdirs();
		}
		PropertyConfigurator.configure(System.getProperty("user.dir")
				+ File.separator + log4jFileName);

	}

	/**
	 * 用指定的路径初始化log4j
	 * @param log4jPath
	 */
	public static void initUseAbsolutePath(String log4jPath) {
		TimeZone.setDefault(TimeZone.getTimeZone("GMT+8:00"));
		File log4j = new File(log4jPath);
		File logDir = new File(log4j.getParent() + File.separator + "logs");
		if (!logDir.exists()) {
			logDir.mkdirs();
		}
		PropertyConfigurator.configure(log4jPath);

	}
}
